package com.kun.demo03;


import org.junit.Test;

import java.text.SimpleDateFormat;

//获得当前时间
public class SleepUse02 {

    @Test
    public void test() {
        getCurrentTime(5);
    }


    public void getCurrentTime(int times) {
        long currentTime = System.currentTimeMillis();
        for (int i = 0; i < times; i++) {
            System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(currentTime));
            try {
                Thread.sleep(1000); //休眠1秒
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            currentTime = System.currentTimeMillis();
        }
    }

}
